/**
 * 
 */
package com.munoor.dalai.server.utils;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * @author Osho. Lok at sending multiple customised mails (e.g greeting based on
 *         username)
 * 
 */
public class Mail {
	public static boolean send(String subject, String body, String name, String address, String fromName, String fromAddress) {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		
		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(fromAddress, fromName));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(address, name));
			msg.setSubject(subject);
			msg.setText(body);
			Transport.send(msg);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

}
